//
//  DoubleViewController.m
//  UIPickerView
//
//  Created by student on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "DoubleViewController.h"

@interface DoubleViewController ()
@property (nonatomic,strong) NSArray *leftList;
@property (nonatomic,strong) NSArray *rightList;

@end

@implementation DoubleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.leftList = @[@"火腿",@"火鸡",@"花生酱",@"金枪鱼沙拉",@"鸡丁沙拉",@"烤牛肉"];
    self.rightList = @[@"白面包",@"粗面粉面包",@"黑麦面包",@"酸面包",@"草莓酱面包"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)btnPressed:(id)sender {
    int sel1 = [self.PickerView selectedRowInComponent:0];
    int sel2 = [self.PickerView selectedRowInComponent:1];
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"选择%@和%@",self.leftList[sel1],self.rightList[sel2]] message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"重新选择",nil];
    [alertView show];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 2;
}

// 第几列有几行?
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftList.count;
    }
    else
    {
        return self.rightList.count;
    }
}
// 第几行第几列是什么内容 加上会显示内容
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if(component == 0)
    {
        return self.leftList[row];
    }
    else
    {
        return self.rightList[row];
    }
}
// 滑动picker时候信息直接显示在Label上面
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    int sel1 = [self.PickerView selectedRowInComponent:0];
    int sel2 = [self.PickerView selectedRowInComponent:1];
   self.infoLabel.text = [NSString stringWithFormat:@"我的早饭是%@和%@",self.leftList[sel1],self.rightList[sel2]];
//    [self.btnPressed setTitle:[NSString stringWithFormat:@"选择%@和%@",self.leftList[sel1],self.rightList[sel2]] forState:UIControlStateNormal];
}


@end
